package com.freesky.provider.order.controller;

import com.freesky.common.pojo.ZTreeNode;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.dao.entity.ItemCat;
import com.freesky.provider.order.service.IItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 10:06 2018/12/14
 * @description:
 */
@RestController
@RequestMapping("/item/cat")
public class ItemCatController {
    @Autowired
    private IItemCatService itemCatService;

    @GetMapping(value = "/list")
    public List<ZTreeNode> getItemCatList(@RequestParam(name="id",defaultValue = "0") int parentId){
        return itemCatService.getItemCatList(parentId);
    }

    @PutMapping(value = "/add")
    public JSONResponse addItemCategory(@RequestBody ItemCat itemCat){

        return itemCatService.addItemCat(itemCat);
    }

    @PostMapping(value = "/update")
    public JSONResponse updateItemCategory(@RequestBody ItemCat itemCat){

        return itemCatService.updateItemCat(itemCat);
    }

    @DeleteMapping(value = "/del/{id}")
    public JSONResponse deleteItemCategory(@PathVariable(value = "id") Long id){
        return itemCatService.deleteItemCat(id);
    }
}
